package com.zking.dto.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data @AllArgsConstructor @NoArgsConstructor
public class ResultDto<T> {
    private int code; // 0或者200都是成功的
    private String message;
    private T data;
    
    public static <U> ResultDto<U> success(U data) {
        ResultDto<U> resultDto = new ResultDto<>();
        resultDto.setCode(0);
        resultDto.setData(data);
        return resultDto;
    }
    
    public static <U> ResultDto<U> fail(int code, String message) {
        ResultDto<U> resultDto = new ResultDto<>();
        resultDto.setCode(code);
        resultDto.setMessage(message);
        return resultDto;
    }
    
    public static <U> ResultDto<U> fail(int code) {
        return fail(code, null);
    }
}